<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购计划商品列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                               采购计划：<select id="purchasePlanId" name="purchasePlanId" class="form-control">
                                <option th:each="purchasePlan : ${purchasePlans}" th:text="${purchasePlan['title']}" th:value="${purchasePlan['purchasePlanId']}" th:field="*{purchasePlan.purchasePlanId}"></option>
                            </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

                <a class="btn btn-danger" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        var resetJieGuo = [[${@permission.hasPermi('system:purchaseitem:jieguo')}]];
        var resetBaoJiaFlag = [[${@permission.hasPermi('system:purchaseitem:baojiadan')}]];
        var list=[[${lists}]];
        console.log(list)
        var prefix = ctx + "system/purchaseitem";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                queryParams: queryParams,
                modalName: "采购计划商品",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'purchaseItemId',
                    title: '采购商品表ID',
                    visible: false
                },
                    {
                        field: 'attribute3',
                        title: '货物分类'
                    },
                {
                    field: 'attribute2',
                    title: '采购计划'
                },
                {
                    field: 'attribute1',
                    title: '货物名称'
                },
                    {
                        field: 'bidStatus',
                        title: '竞价状态',
                        formatter: function(value, row, index) {

                            if(value=='0'){
                                return "竞价成功"
                            }else if(value=='1'){
                                return '竞价中'
                            }else if(value=='-1'){
                                return "竞价失败";
                            }else{
                                return "未开启竞价";
                            }



                        }
                    },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                    {
                        field: 'sysBidinfo.endTime',
                        title: '结束时间'
                    },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        actions.push("<a class='btn btn-default btn-xs " + resetJieGuo + "' href='javascript:void(0)' onclick='jieguo(" + row.purchaseItemId + ")'><i class='fa fa-key'></i>查看报价结果</a> ");
                        actions.push('<a class="btn btn-default btn-xs "' + resetBaoJiaFlag + ' href="javascript:void(0)" onclick="baojiadan(\'' + row.purchaseItemId + '\',\'' + row.sysBidinfo.endTime + '\')"><i class="fa fa-key"></i>报价单</a> ');

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.purchasePlanId = $("#purchasePlanId").val();
            return search;
        }


        function resetPre() {
            $.form.reset();
            $("#purchasePlanId").val($("#purchasePlanId").val()).trigger("change");
        }
        /* 查看报价单 */
        function baojiadan(purchaseItemId,endTime) {

            var dB = new Date(endTime.replace(/-/g, "/"));


            if (new Date() < Date.parse(dB)) {
                $.modal.alertError("竞价时间未结束，请耐心等待！");
            }else {
                var url = prefix + '/baojiadan/' + purchaseItemId;

                $.modal.open("查看报价单", url, '1000', '600');
            }

        }
        /* 查看报价结果 */
        function jieguo(purchaseItemId) {
            var url = prefix + '/jieguo/' + purchaseItemId;
            $.modal.open("查看报价结果", url, '1000', '600');
        }
    </script>
</body>
</html>